set RECV_LISTEN(310) m_320
set RECV_LISTEN(311) m_311
set RECV_LISTEN(312) m_312
set RECV_LISTEN(313) m_320
set RECV_LISTEN(317) m_317
set RECV_LISTEN(318) m_318
set RECV_LISTEN(319) m_319
set RECV_LISTEN(320) m_320

proc m_311 {chid raw parent me} {
	global UHOSTS
	set out [getchan]
	
	regexp {:[^ ]+ 311 [^ ]+ ([^ ]+) ([^ ]+) ([^ ]+) [^ ]+ :(.+)} $raw -> \
		nick user host realname
	
	output $out "\[WHOIS\] $nick [tr is] $nick!$user@$host ($realname)\n" {grey39 italic}
	set UHOSTS($nick) "$user@$host"
}

proc m_312 {chid raw parent me} {
	global CHANS_$chid
	set out [getchan]
	
	regexp {:[^ ]+ 312 [^ ]+ ([^ ]+) ([^ ]+) :(.+)} $raw -> \
		nick server description
	
	output $out "\[WHOIS\] $nick [tr {is on server}] $server ($description)\n" {grey39 italic}
}

proc m_317 {chid raw parent me} {
	global CHANS_$chid
	set out [getchan]
	
	regexp {:[^ ]+ 317 [^ ]+ ([^ ]+) ([0-9]+) ([0-9]+) :(.+)} $raw -> \
		nick s_idle s_signon
	
	set signon [clock format $s_signon -format "%a %b %d %Y %H:%M:%S"]
	set d [expr [clock format $s_idle -format "%e"] - 1]
	set h [expr [clock format $s_idle -format "%k"] - 2]
	set m [clock format $s_idle -format "%M"]
	set s [clock format $s_idle -format "%S"]
	
	regexp {0([0-9])} $s -> s
	regexp {0([0-9])} $m -> m
	
	output $out "\[WHOIS\] $nick [tr {signed on at}] $signon [tr {and has been idle for}] $d [tr days], $h [tr hours], $m [tr minutes] and $s [tr seconds]\n" {grey39 italic}
}

proc m_318 {chid raw parent me} {
	set out [getchan]
	output $out "\[WHOIS\] [tr {End of /WHOIS list}]\n" {grey39 italic}
}

proc m_319 {chid raw parent me} {
	set out [getchan]
	
	regexp {:[^ ]+ 319 [^ ]+ ([^ ]+) :(.+)} $raw -> nick chans
	
	output $out "\[WHOIS\] $nick [tr {is on the following channels}]: $chans\n" {grey39 italic}
}

proc m_320 {chid raw parent me} {
	set out [getchan]
	
	regexp {:[^ ]+ [0-9]+ [^ ]+ ([^ ]+) :(.+)} $raw -> \
		nick msg
	
	output $out "\[WHOIS\] $nick $msg\n" {grey39 italic}
}
